package com.example.myui.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.myui.R;

public class ForResultActivity extends AppCompatActivity {

    private Context mContext;
    private static final String TAG = ForResultActivity.class.getSimpleName();
    private static final int REQUEST_FIRST = 1001;
    private static final int REQUEST_SECOND = 1002;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_for_result);
        mContext = this;
    }

    public void toA(View view) {
        startActivityForResult(new Intent(mContext, FirstActivity.class), REQUEST_FIRST);
    }

    public void toB(View view) {
        startActivityForResult(new Intent(mContext, SecondActivity.class), REQUEST_SECOND);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case REQUEST_FIRST:
                Log.i(TAG, "onActivityResult: " + "a");
                if (resultCode == RESULT_OK) {
                    String first = data.getStringExtra("first");
                    Log.i(TAG, "onActivityResult: " + first);
                }

                break;
            case REQUEST_SECOND:
                Log.i(TAG, "onActivityResult: " + "b");
                if (resultCode == RESULT_OK) {
                    Log.i(TAG, "onActivityResult: " + data.getStringExtra("second"));
                }
                break;
        }
    }
}
